package com.nhc.model;

import android.content.Context;
import android.content.SharedPreferences;

import zuo.biao.library.util.JSON;

public class LambertParmFileHandle {

    private static LambertParmFileHandle instance = new LambertParmFileHandle();

    public static LambertParmFileHandle getInstance() {
        return instance;
    }

    public boolean OneStandPar = true;//Lambert-0
    public LambertSetInfo lambert0 = new LambertSetInfo();
    public LambertSetInfo lambert1 = new LambertSetInfo();

    public int stereograph = 0;//Stereograph
    public LambertSetInfo stereograph0 = new LambertSetInfo();
    public LambertSetInfo stereograph1 = new LambertSetInfo();
    public LambertSetInfo stereograph2 = new LambertSetInfo();
    public LambertSetInfo stereograph3 = new LambertSetInfo();

    public LambertSetInfo polyconic = new LambertSetInfo();

    public LambertSetInfo mLambertSetInfoEdit = new LambertSetInfo();

    //Lambert+ Stereograph
    public LambertParmFileHandle() {

    }

    private String LAMBERTPARM = "LambertParm";

    public void save(Context context) {
        if (context == null) {
            return;
        }

        SharedPreferences sp = context.getSharedPreferences(
                LAMBERTPARM, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString("lambert0", JSON.toJSONString(lambert0));
        editor.putString("lambert1", JSON.toJSONString(lambert1));
        editor.putString("stereograph0", JSON.toJSONString(stereograph0));
        editor.putString("stereograph1", JSON.toJSONString(stereograph1));
        editor.putString("stereograph2", JSON.toJSONString(stereograph2));
        editor.putString("stereograph3", JSON.toJSONString(stereograph3));
        editor.putString("polyconic", JSON.toJSONString(polyconic));
        editor.putInt("stereograph", stereograph);
        editor.putBoolean("OneStandPar", OneStandPar);
        editor.commit();
    }

    public void load(Context context) {
        if (context == null) {
            return;
        }

        SharedPreferences sp = context.getSharedPreferences(
                LAMBERTPARM, Context.MODE_PRIVATE);
        String strlambert0 = sp.getString("lambert0", "");
        String strlambert1 = sp.getString("lambert1", "");
        String strstereograph0 = sp.getString("stereograph0", "");
        String strstereograph1 = sp.getString("stereograph1", "");
        String strstereograph2 = sp.getString("stereograph2", "");
        String strstereograph3 = sp.getString("stereograph3", "");
        String strpolyconic = sp.getString("polyconic", "");

        stereograph = sp.getInt("stereograph", 0);
        OneStandPar = sp.getBoolean("OneStandPar", true);

        try {
            if (strlambert0.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strlambert0);
                if (data != null) {
                    lambert0 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strlambert1.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strlambert1);
                if (data != null) {
                    lambert1 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strstereograph0.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strstereograph0);
                if (data != null) {
                    stereograph0 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strstereograph1.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strstereograph1);
                if (data != null) {
                    stereograph1 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strstereograph2.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strstereograph2);
                if (data != null) {
                    stereograph2 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strstereograph3.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strstereograph3);
                if (data != null) {
                    stereograph3 = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
            if (strpolyconic.length() > 1) {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strpolyconic);
                if (data != null) {
                    polyconic = JSON.parseObject(data, LambertSetInfo.class);
                }
            }
        } catch (Exception e1) {

        }


    }


}